
const express=require("express");
const app=express();
// bodypaser中间件s
const bodypaser=require("body-parser");
app.use(bodypaser.urlencoded({extended:false}));
//express-session中间件;
const session=require("express-session");
app.use(session({
    secret:"zxzxzx",
    resave:false,
    saveUninitialized:false
}))
const fs=require("fs");
const path=require("path");


// 托管静态资源(html,css,js);
app.use("/node_modules",express.static("./node_modules"));
// 创建模板
app.set("view engine","ejs");
app.set("views","./views");
// 监听
// const router1=require("./router/index.js");
// app.use(router1);

// const router2=require("./router/user.js");
// app.use(router2);

fs.readdir(path.join(__dirname,"./router"),(err,filename)=>{
    if(err) return console.log("读取失败");
    console.log(filename);
    filename.forEach(item=>{
        const router=require("./router/"+item);
         app.use(router);
    })

})
app.listen(80,()=>{
    console.log("启动成功");
})